﻿// ******************************************************************************************************
// <copyright file="Interval2D.cs" company="Caroso.inc">
//     Copyright (c) Carlos Osorio All rights reserved.
// </copyright>
// ******************************************************************************************************
// The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); 
// you may not use this file except in compliance with the License. You may obtain a copy of the License at 
// http:// www.mozilla.org/MPL/ 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 
// ANY KIND, either express or implied. See the License for the specificlanguage governing rights and 
// limitations under the License. 
// 
// The Original Code is this .mapWindow 
// 
// The Initial Developer of this version of the Original Code is Carlos Osorio carosocali@gmail.com
// 
// Contributor(s): (Open source contributors should list themselves and their modifications here). 
// Change Log: 
// Date           Changed By      Notes
// 6 jun 2011    Carlos Osorio   Inital upload t
// ******************************************************************************************************
namespace GeostatisticalTool.Classes
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// This evaluates an interval in two dimensions
    /// </summary>
    public class Interval2D
    {
        /// <summary>
        /// Interval in the axe X
        /// </summary>
        public readonly Interval IntervalX;

        /// <summary>
        /// Interval in the axe Y
        /// </summary>
        public readonly Interval IntervalY;

        public readonly Interval IntervalZ;

        /// <summary>
        /// Initializes a new instance of the Interval2D class
        /// </summary>
        /// <param name="intervalX">Interval in the axe X </param>
        /// <param name="intervalY">Interval in the axe Y</param>
        public Interval2D(
            Interval intervalX, Interval intervalY, Interval intervalZ)
        {
            this.IntervalX = intervalX;
            this.IntervalY = intervalY;
            this.IntervalZ= intervalZ;
        }

        /// <summary>
        /// Evaluates if the interval2D intersects
        /// </summary>
        /// <param name="b">Evaluate the interval b</param>
        /// <returns>True if the invertals are intersected</returns>
        public bool Intersects(
            Interval2D b)
        {
            if (this.IntervalX.Intersects(b.IntervalX))
            {
                return true;
            }

            if (this.IntervalY.Intersects(b.IntervalY))
            {
                return true;
            }

            return false;
        }

        /// <summary>
        /// Evaluates if the interval2D is contained
        /// </summary>
        /// <param name="x">Evaluate the value in X</param>
        /// <param name="y">Evaluate the value in Y</param>
        /// <returns>True if the value x and y is contained</returns>
        public bool Contains(
            double x, double y)
        {
            return this.IntervalX.Contains(x) && this.IntervalY.Contains(y);
        }

        /// <summary>
        /// Override the method String
        /// </summary>
        /// <returns>Return the Interval2D</returns>
        public override string ToString()
        {
            return this.IntervalX.ToString() + " x " + this.IntervalY.ToString();
        }
    }
}
